﻿/***************************************************************************
 *		ElGee Google Chart API Helper
 *		Copyright(C) 2011 by Laurent Geffroy lgeffroy@gmail.com
 * 
 *		This program is free software; you can redistribute it and/or 
 *		modify it under the terms of the GNU General Public License as
 *		published by the Free Software Foundation; either version 2 of 
 *		the License, or (at your option) any later version.
 *		
 *		This program is distributed WITHOUT ANY WARRANTY; without even the
 *		implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 *		See the GNU General Public License for more details.
 *	
 *      For particular licensing, please contact me at lgeffroy@gmail.com
 *****************************************************************************/

using System;
using System.Collections.Generic;
using System.Text;

namespace ElGee.Google.Charts
{
    /// <summary>
    /// Style for the Geo Map
    /// </summary>
    public class GeoMapStyle : BaseChartStyle
    {

        /// <summary>
        /// Gets or sets the data mode.
        /// How to display values on the map. Two values are supported:
        /// regions - Colors a whole region with the appropriate color. This option cannot be used with latitude/longitude addresses. See Regions Example.
        /// markers - Displays a dot over a region, with the color and size indicating the value. See Markers Example.
        /// </summary>
        /// <value>The data mode.</value>
        public TypeOfDataMode DataMode { get; set; }


        /// <summary>
        /// Gets or sets the region.
        /// The area to display on the map. (Surrounding areas will be displayed as well.) Can be either a country code (in uppercase ISO-3166 format), or a one of the following strings:
        /// world - (Whole world)
        /// us_metro - (United States, metro areas)
        /// 005 - (South America)
        /// 013 - (Central America)
        /// 021 - (North America)
        /// 002 - (All of Africa)
        /// 017 - (Central Africa)
        /// 015 - (Northern Africa)
        /// 018 - (Southern Africa)
        /// 030 - (Eastern Asia)
        /// 034 - (Southern Asia)
        /// 035 - (Asia/Pacific region)
        /// 143 - (Central Asia)
        /// 145 - (Middle East)
        /// 151 - (Northern Asia)
        /// 154 - (Northern Europe)
        /// 155 - (Western Europe)
        /// 039 - (Southern Europe)
        /// Geomap does not enable scrolling or dragging behavior, and only limited zooming behavior. A basic zoom out can be enabled by setting the showZoomOut property.
        /// </summary>
        /// <value>The region.</value>
        public String Region { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether [show legend].
        /// If true, display a legend for the map.
        /// </summary>
        /// <value><c>true</c> if [show legend]; otherwise, <c>false</c>.</value>
        public bool ShowLegend { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether [show zoom out].
        /// If true, display a button with the label specified by the zoomOutLabel property. Note that this button does nothing when clicked, except throw the zoomOut event. To handle zooming, catch this event and change the region option. You can only specify showZoomOut if the region option is smaller than the world view. One way of enabling zoom in behavior would be to listen for the regionClick event, change the region property to the appropriate region, and reload the map.
        /// </summary>
        /// <value><c>true</c> if [show zoom out]; otherwise, <c>false</c>.</value>
        public bool ShowZoomOut { get; set; }

        /// <summary>
        /// Gets or sets the zoom out label.
        /// Label for the zoom button.
        /// </summary>
        /// <value>The zoom out label.</value>
        public String ZoomOutLabel { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="GeoMapStyle"/> class.
        /// </summary>
        /// <param name="colors">The colors. You must have at least two values; the gradient will include all your values, plus calculated intermediary values, with the lightest color as the smallest value, and the darkest color as the highest.
        /// Default values are 0xE0FFD4, 0xA5EF63, 0x50AA00 and 0x267114
        /// </param>
        public GeoMapStyle(List<String> colors) : base()
        {
            Region = "world";
            ShowLegend = true;
            DataMode = TypeOfDataMode.Undefined;
            ZoomOutLabel = "Zoom Out";
            Width = 556;
            Height = 347;
            if ((colors == null) || (colors.Count < 2))
            {
                Colors = new List<string>();
                Colors.Add("0xE0FFD4");
                Colors.Add("0xA5EF63");
                Colors.Add("0x50AA00");
                Colors.Add("0x267114");
            }
            else
                Colors = colors;
        }

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            string baseParams = base.ToString();
            if (!String.IsNullOrWhiteSpace(baseParams))
                sb.Append(baseParams).Append(",");

            // Region
            if ((!String.IsNullOrWhiteSpace(Region)) && (Region.ToLower() != "world"))
                sb.Append("region: '").Append(SecureString(Region)).Append("',");

            // DataMode
            if (DataMode == TypeOfDataMode.Markers)
                sb.Append("dataMode: 'markers',");

            if (!ShowLegend)
                sb.Append("showLegend: false,");

            if (ShowZoomOut)
            {
                sb.Append("showZoomOut: true,");
                sb.Append("zoomOutLabel: '").Append(SecureString(ZoomOutLabel)).Append("',");
            }

            // Removing the last comma
            sb.Remove(sb.Length - 1, 1);

            return sb.ToString();
        }
    }
}
